<?php


namespace server\impl;


use common\core\server\BaseServer;
use common\helpers\DictHelper;
use server\dao\Log;
use server\dao\RemoteLoginLog;
use server\dao\Runtime;
use server\dao\SysLoginLog;
use server\dao\SysOperationLog;
use server\LogInterface;
use Yii;
use yii\mongodb\Exception;

class LogImpl extends BaseServer implements LogInterface
{
    protected $log;
    protected $runtime;
    protected $login_log;
    protected $operation_log;
    protected $remote_login_log;

    public function __construct(array $config = [])
    {
        $this->log = new Log();
        $this->runtime = new Runtime();
        $this->login_log = new SysLoginLog();
        $this->operation_log = new SysOperationLog();
        $this->remote_login_log = new RemoteLoginLog();
        parent::__construct($config);
    }

    public function loginLog($params = [])
    {
        return  $this->login_log->getLoginLog($params);

    }

    public function operationLog($params = [])
    {
        return $this->operation_log->getOperationLog($params);
    }

    public function queryLog($params, $isAll = false)
    {
        try {
            Yii::$app->mongodb->createCommand()->createCollection('log');
        } catch (Exception $e) {

        }
        return $log = $this->log->getLogList($params, $isAll);
    }

    public function queryRuntime($params = [], $isAll = false)
    {
        try {
            Yii::$app->mongodb->createCommand()->createCollection('runtime');
        } catch (Exception $e) {

        }
        return $this->runtime->getRuntimeList($params, $isAll);

    }

    public function queryLastRuntimeByIps(array $ips){
        try {
            Yii::$app->mongodb->createCommand()->createCollection('runtime');
        } catch (Exception $e) {

        }
        return $this->runtime->getLastRuntimeGroupId($ips);;

    }

    public function insertRemoteLoginLog(array $data){
        return $this->remote_login_log->setRemoteLoginLog($data);
    }

    public function queryRemoteLoginLog($params, $isAll = false)
    {
        return  $this->remote_login_log->getRemoteLoginLog($params);

    }

    public function getLogModule()
    {
        return $this->log->getLogModule();
    }


}